package com.ruoyi.xh.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TablePageDataInfo;
import com.ruoyi.common.core.domain.CommentResult;
import com.ruoyi.xh.domain.XhSpec;
import com.ruoyi.xh.service.IXhSpecService;

/**
 * 规格信息Controller
 *
 * @author songjw
 * @date 2024-12-13
 */
@Api(tags = "规格信息Controller",value = "规格信息Controller")
@RestController
@RequestMapping("/xh/spec")
public class XhSpecController extends BaseController {

    @Autowired
    private IXhSpecService xhSpecService;

    /**
     * 查询规格信息列表
     */
    @PreAuthorize("@ss.hasPermi('xh:spec:list')")
    @GetMapping("/list")
    @ApiOperation("查询规格信息列表")
    public TablePageDataInfo<XhSpec> list(XhSpec xhSpec) {
        return TablePageDataInfo.success(xhSpecService.selectXhSpecList(xhSpec));
    }

    /**
     * 获取规格信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('xh:spec:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取规格信息详细信息")
    public CommentResult<XhSpec> getInfo(@PathVariable("id") Long id) {
        return CommentResult.success(xhSpecService.selectXhSpecById(id));
    }

    /**
     * 新增规格信息
     */
    @PreAuthorize("@ss.hasPermi('xh:spec:add')")
    @Log(title = "规格信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增规格信息")
    public CommentResult<XhSpec> add(@RequestBody XhSpec xhSpec) {
            xhSpecService.insertXhSpec(xhSpec);
        return CommentResult.success();
    }

    /**
     * 修改规格信息
     */
    @PreAuthorize("@ss.hasPermi('xh:spec:edit')")
    @Log(title = "规格信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改规格信息")
    public CommentResult<XhSpec> edit(@RequestBody XhSpec xhSpec) {
            xhSpecService.updateXhSpec(xhSpec);
        return CommentResult.success();
    }

    /**
     * 删除规格信息
     */
    @PreAuthorize("@ss.hasPermi('xh:spec:remove')")
    @Log(title = "规格信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除规格信息")
    public CommentResult<XhSpec> remove(@PathVariable Long[] ids) {
            xhSpecService.deleteXhSpecByIds(ids);
        return CommentResult.success();
    }
}
